package com.bb.blog.rabbitmq;

import com.bb.blog.rabbitmq.config.RabbitMqConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;


@Component
public class MyConsumer {
    private static Logger logger = LoggerFactory.getLogger(MyConsumer.class);

    public MyConsumer() {
        logger.info("初始化消费者");
    }


    /**
     * 消费者
     *
     * @param message
     */
    @RabbitListener(queues = {RabbitMqConfig.QUEUE_1, RabbitMqConfig.QUEUE_2, RabbitMqConfig.QUEUE_3, RabbitMqConfig.QUEUE_DEAD})
    @RabbitHandler
    public void processFanoutMessage(Message message) {
        message.getMessageProperties().getConsumerQueue();
        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
        logger.info("received Fanout message : " + msg);
    }

}
